package liangtWorkSpace.threadDemo.thread.JUC;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author liangt
 * @ClassName: ThreadScheduled
 * @title: ThreadScheduled
 * @projectName liangtWorkSpace.threadDemo.thread.JUC
 * @description: TODO
 * @date 2020/11/5 13:14
 */
public class ThreadScheduled {
    public static void main(String[] args) {
        //延时定时执行
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);

        //延迟三秒调用一次
        final int index = 1;
        scheduledExecutorService.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + ":" + index);
            }
        }, 3, TimeUnit.SECONDS);

        //延迟一秒。每三秒调用一次
        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + ":" + index);
            }
        },1,3,TimeUnit.SECONDS);
//        scheduledExecutorService.shutdown();
    }


}
